package 牛客网_N.动态规划.魔术索引_2;
/**
 * 递归
 */
import java.util.Scanner;

public class Main3 {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int n = Integer.parseInt(in.nextLine());
		String str = in.nextLine();
		String[] dataStr = str.split(" ");
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = Integer.parseInt(dataStr[i]);
		}
		boolean b = magic(a, 0, n);
		System.out.println(b);
	}
	public static boolean magic(int[] a, int start, int end){
		if(!(start < end)) return false;
		int mid = (start+end)/2;
		if(a[mid] > mid) return magic(a, start, mid);
		if(a[mid] < mid) return magic(a, mid, end);
		return true;
	}
}
